using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace rocketjump
{
    class MainMenu
    {
        Texture2D face;
        Texture2D blinking;
        Texture2D logo;
        int animationFrame = 0;
        bool animation = false;
        int timeToNextAnimation;
        int timeToNextBlink;
        int timeToNextBlinking;
        int timeToNextFrame;
        SpriteFont uiFontLarge;
        bool blink, blink2;
        int blinkFrame = 0;

        public void loadContent(ContentManager content)
        {
            face = content.Load<Texture2D>("graphics/mainmenu/sammy_introscreen");
            logo = content.Load<Texture2D>("graphics/mainmenu/anim_logo_776");
            blinking = content.Load<Texture2D>("graphics/mainmenu/anim_glitterfx_64");
            timeToNextAnimation = 1000;
            timeToNextBlink = 1000;
            uiFontLarge = content.Load<SpriteFont>("fonts/UIFontLarge");
        }

        public void draw(SpriteBatch spriteBatch)
        {
            GraphicsHelper.BeginBatch();
            spriteBatch.Draw(face, new Rectangle(482, 20, face.Width, face.Height), Color.White);
            spriteBatch.Draw(logo, new Rectangle(0, 0, 776, 160), new Rectangle(776 * (animationFrame % 2), 160 * (animationFrame / 2), 776, 160), Color.White);
            if (blink2)
                spriteBatch.Draw(blinking, new Rectangle(620, 235, 64, 64), new Rectangle(64 * (blinkFrame % 7), 0, 64, 64), Color.White);
            if (blink)
                spriteBatch.DrawString(uiFontLarge, "TAP YOU *$@#!", new Vector2(20, 340), Color.White);
            spriteBatch.DrawString(uiFontLarge, "papanavaappu@gmail.com", new Vector2(10, 420), Color.Gray);
        }

        public void update(GameTime gameTime)
        {
            timeToNextAnimation -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timeToNextAnimation < 0)
            {
                animation = true;
                timeToNextFrame = 30;
                timeToNextAnimation = 3000;
            }
            timeToNextBlink -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timeToNextBlink < 0)
            {
                if (blink)
                    blink = false;
                else
                    blink = true;
                timeToNextBlink = 500;
            }
            timeToNextBlinking -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timeToNextBlinking < 0)
            {
                blink2 = true;
                timeToNextBlinking = 4000;
            }
            if (blink2 && blinkFrame < 7)
            {
                if (timeToNextBlinking % 4 == 0)
                {
                    blinkFrame++;
                }
           }
            else if(7 <= blinkFrame)
            {
                blink2 = false;
                blinkFrame = 0;
            }
            if (animation == true)
            {
                timeToNextFrame -= (int)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (timeToNextFrame < 0)
                {
                    animationFrame++;
                    timeToNextFrame = 30;
                    if (animationFrame > 8)
                    {
                        animation = false;
                        animationFrame = 0;
                    }
                }
            }
        }
    }
}
